<?php
class Lugare extends AppModel {
    var $name = 'Lugare';
	
    function generateCodigo(){
		$result = $this->query('select 
									COALESCE(cast(max(d.codigo) as integer)+1,1) as "Lugare__codigo" 
								from expedientes.lugares d 
								where d.activo = true');
		$result = $result[0];
		return str_repeat('0',4-strlen($result['Lugare']['codigo'])).$result['Lugare']['codigo'];			
	}
}
?>